
local getmetatable = getmetatable
local setmetatable = setmetatable
local module = module
local require = require
local print = print
local type = type
local error = error
local string = string
local pcall = pcall
local tonumber = tonumber

module('eg.music.Browser')
_VERSION='0.1'

local Fixture = require('fit.Fixture')
local MusicLibrary = require('eg.music.MusicLibrary')

local function library(self, path)
    self.music.loadFile(self.music, path)
end


local function totalSongs(self)
    return #(self.music.library)
end

local function select(self, i)
    self.music.select(self.music, self.music.library[tonumber(i)])
end

local function title(self)
    return self.music.looking.title
end

local function artist(self)
    return self.music.looking.artist
end

local function album(self)
    return self.music.looking.album
end

local function year(self)
    return self.music.looking.year
end

local function time(self)
    return self.music.looking.time(self.music.looking)
end

local function track(self)
    return self.music.looking.track(self.music.looking)
end

local function sameAlbum(self)
    self.music:findAlbum(self.music.looking.album)
end

local function sameArtist(self)
    self.music:findArtist(self.music.looking.artist)
end

local function sameGenre(self)
    self.music:findGenre(self.music.looking.genre)
end

local function sameYear(self)
    self.music:findYear(self.music.looking.year)
end

local function selectedSongs(self)
    return self.music:displayCount()
end

function __call()
    local browser = Fixture()

    browser.library = library
    browser.totalSongs = totalSongs
    browser.select = select
    browser.title = title
    browser.artist = artist
    browser.album = album
    browser.year = year
    browser.time = time
    browser.track = track
    browser.sameAlbum = sameAlbum
    browser.sameArtist = sameArtist
    browser.sameGenre = sameGenre
    browser.sameYear = sameYear
    browser.selectedSongs = selectedSongs

    browser.music = MusicLibrary()
    browser.name = "eg.music.Browser"

    return browser
end

setmetatable(_M, _M)
